﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Yipusoft.TownshipEnterprise.BLL;
using Yipusoft.TownshipEnterprise.DBUtility;
using System.Data.SqlClient;

public partial class TownshipEnterprise_TownStat : System.Web.UI.Page
{
    string deptid = string.Empty;
    string flag = string.Empty;
    public String TdTitle= "";
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {

            deptid = Request.QueryString["DepartmentID"].ToString();
            flag = Request.QueryString["Flag"].ToString();
            if (flag == "1")
            {
                DBCls db = new DBCls();
                TdTitle = db.QueryDataTable("SELECT distinct  dpt_szd  FROM View_TownDept WHERE left(DepartmentID,4)='" + deptid + "'", "dpt_szd").Rows[0][0].ToString().Trim() + "市专职队汇总表";
            }
            else
            {
                flag = "0";
                TdTitle = "全省专职队汇总表";
            }
            
        }
        catch(Exception ex)
        {
            flag = "0";
            TdTitle = "全省专职队汇总表";
        }
        init(flag);
        BoundTable(deptid,flag );
    }
    HtmlTableRow tr;
    HtmlTableCell td;
    HtmlAnchor anchor;
    void init(String _flag)
    {

        tr = new HtmlTableRow();
        tr.Cells.Add(new HtmlTableCell());
        if(_flag=="0")
            tr.Cells[0].InnerText = "地市";
        else
            tr.Cells[0].InnerText = "区县";
        tr.Cells[0].Attributes.Add("rowspan", "2");
        tr.Cells[0].Attributes.Add("align", "center");
        tr.Cells[0].Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
        tr.Cells.Add(new HtmlTableCell());
        tr.Cells[1].InnerText = "乡镇四有消防队";
        tr.Cells[1].Attributes.Add("colspan", "4");
        tr.Cells[1].Attributes.Add("align", "center");
        tr.Cells[1].Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
        tr.Cells.Add(new HtmlTableCell());
        tr.Cells[2].InnerText = "企事业专职消防队";
        tr.Cells[2].Attributes.Add("colspan", "4");
        tr.Cells[2].Attributes.Add("align", "center");
        tr.Cells[2].Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
        table1.Rows.Add(tr);
        tr = new HtmlTableRow();
        tr.Cells.Add(new HtmlTableCell());
        tr.Cells[0].InnerText = "数量";
        tr.Cells[0].Attributes.Add("align", "center");
        tr.Cells[0].Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
        tr.Cells.Add(new HtmlTableCell());
        tr.Cells[1].InnerText = "人数";
        tr.Cells[1].Attributes.Add("align", "center");
        tr.Cells[1].Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
        tr.Cells.Add(new HtmlTableCell());
        tr.Cells[2].InnerText = "车辆";
        tr.Cells[2].Attributes.Add("align", "center");
        tr.Cells[2].Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
        tr.Cells.Add(new HtmlTableCell());
        tr.Cells[3].InnerText = "器材";
        tr.Cells[3].Attributes.Add("align", "center");
        tr.Cells[3].Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
        tr.Cells.Add(new HtmlTableCell());
        tr.Cells[4].InnerText = "数量";
        tr.Cells[4].Attributes.Add("align", "center");
        tr.Cells[4].Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
        tr.Cells.Add(new HtmlTableCell());
        tr.Cells[5].InnerText = "人数";
        tr.Cells[5].Attributes.Add("align", "center");
        tr.Cells[5].Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
        tr.Cells.Add(new HtmlTableCell());
        tr.Cells[6].InnerText = "车辆";
        tr.Cells[6].Attributes.Add("align", "center");
        tr.Cells[6].Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
        tr.Cells.Add(new HtmlTableCell());
        tr.Cells[7].InnerText = "器材";
        tr.Cells[7].Attributes.Add("align", "center");
        tr.Cells[7].Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
        table1.Rows.Add(tr);
    }

    void BoundTable(String _dept,String _flag)
    {
        SqlParameter[] parameters = {
                new SqlParameter("@type",SqlDbType.NVarChar,1),
                new SqlParameter("@City",SqlDbType.NVarChar,4)
            };
        parameters[1].Value = _dept;
        parameters[0].Value = _flag;
        using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
        {
            SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "TownSumCount", parameters);
            while (dr.Read())
            {
                tr = new HtmlTableRow();
                td = new HtmlTableCell();
                String pag = "TownStat";
                String fg = "1";
                if (_flag == "1")
                {
                    pag = "AllList";
                    fg = "0";
                }
                HtmlAnchor anchor = new HtmlAnchor();
                anchor.InnerText = dr["dptname"].ToString();
                anchor.HRef = pag + ".aspx?DepartmentID=" + dr["DEPENDENTid"].ToString() + "&Flag=" + fg;
                td.Controls.Add(anchor);
                td.Attributes.Add("align", "center");
                td.Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
                tr.Cells.Add(td);

                td = new HtmlTableCell();
                anchor = new HtmlAnchor();
                anchor.InnerText = dr["sy_bcount"].ToString();
                anchor.HRef = "AllList.aspx?DepartmentID=" + dr["DEPENDENTid"].ToString() + "&Flag=2";
                td.Controls.Add(anchor);
                td.Attributes.Add("align", "center");
                td.Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
                tr.Cells.Add(td);

                td = new HtmlTableCell();
                anchor = new HtmlAnchor();
                anchor.InnerText = dr["sy_mcount"].ToString();
                anchor.HRef = "AllList.aspx?DepartmentID=" + dr["DEPENDENTid"].ToString() + "&Flag=2";
                td.Controls.Add(anchor);
                td.Attributes.Add("align", "center");
                td.Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
                tr.Cells.Add(td);

                td = new HtmlTableCell();
                anchor = new HtmlAnchor();
                anchor.InnerText = dr["sy_vcount"].ToString();
                anchor.HRef = "VehicleList.aspx?Where=DepartmentID like '" + dr["DEPENDENTid"].ToString() + "%' and FBType='乡镇四有消防队'&cap=" + dr["dptname"].ToString() + " 乡镇四有消防队";
                td.Controls.Add(anchor);
                td.Attributes.Add("align", "center");
                td.Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
                tr.Cells.Add(td);

                td = new HtmlTableCell();
                anchor = new HtmlAnchor();
                anchor.InnerText = dr["sy_dcount"].ToString();
                anchor.HRef = "DeviceList.aspx?Where=DepartmentID like '" + dr["DEPENDENTid"].ToString() + "%' and FBType='乡镇四有消防队'&cap=" + dr["dptname"].ToString() + " 乡镇四有消防队";
                td.Controls.Add(anchor);
                td.Attributes.Add("align", "center");
                td.Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
                tr.Cells.Add(td);

                td = new HtmlTableCell();
                anchor = new HtmlAnchor();
                anchor.InnerText = dr["qsy_bcount"].ToString();
                anchor.HRef = "AllList.aspx?DepartmentID=" + dr["DEPENDENTid"].ToString() + "&Flag=1";
                td.Controls.Add(anchor);
                td.Attributes.Add("align", "center");
                td.Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
                tr.Cells.Add(td);

                td = new HtmlTableCell();
                anchor = new HtmlAnchor();
                anchor.InnerText = dr["qsy_mcount"].ToString();
                anchor.HRef = "AllList.aspx?DepartmentID=" + dr["DEPENDENTid"].ToString() + "&Flag=1";
                td.Controls.Add(anchor);
                td.Attributes.Add("align", "center");
                td.Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
                tr.Cells.Add(td);

                td = new HtmlTableCell();
                anchor = new HtmlAnchor();
                anchor.InnerText = dr["qsy_vcount"].ToString();
                anchor.HRef = "VehicleList.aspx?Where=DepartmentID like '" + dr["DEPENDENTid"].ToString() + "%' and FBType='企事业专职消防队'&cap=" + dr["dptname"].ToString() + " 企事业专职消防队";
                td.Controls.Add(anchor);
                td.Attributes.Add("align", "center");
                td.Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
                tr.Cells.Add(td);

                td = new HtmlTableCell();
                anchor = new HtmlAnchor();
                anchor.InnerText = dr["qsy_dcount"].ToString();
                anchor.HRef = "DeviceList.aspx?Where=DepartmentID like '" + dr["DEPENDENTid"].ToString() + "%' and FBType='企事业专职消防队'&cap=" + dr["dptname"].ToString() + " 企事业专职消防队";
                td.Controls.Add(anchor);
                td.Attributes.Add("align", "center");
                td.Attributes.Add("style", "border-color:#CEE7F7;border-collapse: collapse;  border-width: 1px; border-style:solid;");
                tr.Cells.Add(td);
                table1.Rows.Add(tr);
            }
        }
        
    }



}
